package datastructure.graph.无向图;

import datastructure.Bag;

/**
 * @author MaoLin Wang
 * @description
 * @date 2020/8/27 12:50 下午
 */
public class Graph {

    private int v;
    private int e;
    private Bag<Integer>[] adv;

    public Graph(int v) {
        this.v = v;
        adv=new Bag[v];
        for (int i = 0; i < v; i++) {
            adv[i]=new Bag<>();
        }
    }
    public boolean hasEdge(int v,int w){
        for (Integer i : adv[v]) {
            if (i==w){
                return true;
            }
        }
        return false;
    }

    public int getV() {
        return v;
    }
    public Iterable<Integer> adj(int v){
        return adv[v];
    }

    public void setV(int v) {
        this.v = v;
    }

    public int getE() {
        return e;
    }

    public void setE(int e) {
        this.e = e;
    }

    public void addEdge(int v, int w) {
        if (v==w){
            return;
        }else if (hasEdge(v,w)){
            return;
        }
        adv[v].add(w);
        adv[w].add(v);
        e++;
    }
}
